package com.example.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.example.entity.Speciality;
import com.example.mapper.SpecialityMapper;
import com.example.service.SpecialityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SpecialityServiceImpl implements SpecialityService {
    @Resource
    private SpecialityMapper specialityMapper;
    @Override
    public void add(Speciality speciality) {
        specialityMapper.insert(speciality);
    }

    @Override
    public PageInfo<Speciality> selectPage(Integer pageNum, Integer pageSize, String name) {
        List<Speciality> list = null;
        PageHelper.startPage(pageNum, pageSize);
        //1.name有值，按照name进行模糊查询
        if (ObjectUtil.isNotEmpty(name)) {
            list = specialityMapper.selectByName(name);
        }else {
            //2.name为空，查询所有
            list = specialityMapper.selectAll();
        }
        return PageInfo.of(list);
    }

    @Override
    public List<Speciality> selectAll() {
        return specialityMapper.selectAll();
    }

    @Override
    public void updateById(Speciality speciality) {
        specialityMapper.updateById(speciality);
    }

    @Override
    public void deleteById(Integer id) {
        specialityMapper.deleteById(id);
    }
}
